<template>
  <section>
    <van-sticky>
      <PageHeader title="线下活动报名"/>
    </van-sticky>

    <van-list
      class="mt10"
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="requestData">
      <div class="flex flex-row pd10 border-bottom-gray bg-color-white apply-item" v-for="(item, index) in dataList" :key="index">
        <img :src="item.user.avatar_url ? item.user.avatar_url : BASE_STATIC_URL + 'images/mp/avatar.jpeg'" class="flex avatar" />
        <div class="flex flex-col flex-1 pl10 font-common">
          <div class="flex flex-row flex-left">{{item.user.nick}}</div>
          <div class="flex flex-row flex-left mt10">报名时间:{{item.apply_time|timeFormat('yyyy-MM-dd hh:mm:ss')}}</div>
        </div>
      </div>
    </van-list>
  </section>
</template>

<script>
  import Vue from 'vue';
  import {Toast, Dialog, List, Search, Sticky} from 'vant';
  import {activityApplyListsUri, BASE_STATIC_URL} from "../../common/api";
  import PageHeader from "../componets/PageHeader";
  Vue.use(Toast).use(Dialog).use(List).use(Search).use(Sticky);


  export default {
    components: {
      PageHeader
    },
    data() {
      return {
        BASE_STATIC_URL: BASE_STATIC_URL,
        currentPage: 1,
        lastPage: 0,
        total: 0,
        pageSize: 10,
        loading: false,
        finished: false,
        dataList: []
      }
    },
    methods: {
      requestData() {
        const that = this;
        this.loading = true;
        const url = activityApplyListsUri + '?page_size=' + that.pageSize + '&page=' + that.currentPage + '&activity_id=' + this.$route.params.activityId;
        this.$http.get(url).then(response => {
          let {code, msg, data} = response.body
          if (code != 0) {
            Toast.fail(msg);
          } else {
            that.loading = false;
            if (that.currentPage >= data.last_page) {
              that.finished = true;
            }
            that.currentPage = that.currentPage + 1;
            for (let i = 0; i < data.data.length; i++) {
              that.dataList.push(data.data[i]);
            }
            that.total = data.total;
            that.lastPage = data.last_page;
          }
        }, response => {
          // error callback
        })
      }
    },
    mounted: function () {

    }
  }
</script>

<style scoped>
  .apply-item .avatar {
    height: 50px;
    width: 50px;
    border-radius: 25px;
  }
</style>
